<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>菜单详情</title>
  <link rel="stylesheet" href="./css/style.css" />
</head>

<body>
  <h3 class="big-tit">菜谱详情</h3>
  <div class="container flex-box">
    <div class="left">
      <img src="http://yun.itheima.com/Upload/Images/20220627/62b924298e658.jpg" alt="" />
    </div>
    <div class="right">
      <h3>菜谱名称</h3>
      <p>
        <!-- 菜谱描述信息 -->
      </p>
      <h5>下面列表是菜谱中美味的菜品哦！</h5>
    </div>
  </div>
  <ul class="list-box">
    <!-- <li>
      <a href="detail.html">
        <img src="http://yun.itheima.com/Upload/Images/20220627/62b924298e658.jpg" alt="" />
        <h3>菜单名称</h3>
      </a>
    </li>
    
    <li>
      <a href="detail.html">
        <img src="http://yun.itheima.com/Upload/Images/20220627/62b924298e658.jpg" alt="" />
        <h3>菜单名称</h3>
      </a>
    </li> -->
  </ul>
</body>

<script src="./JS/jquery.js"></script>
<script src="./JS/axios.js"></script>
<script>

  const id = localStorage.getItem('idajax06')
  axios.defaults.baseURL = 'http://124.223.14.236:3001/api'

  async function getList() {
    const { data: { data } } = await axios.get(`/recipe/${id}`)
    //console.log(data);
    const dataStr =
      `
      <div class="left">
        <img src="http://124.223.14.236:3001/public/${data.img}" alt="" />
      </div>
      <div class="right">
        <h3>${data.name}</h3>
        <p>
      ${data.description}
        </p>
        <h5>下面列表是菜谱中美味的菜品哦！</h5>
      </div>
      `
    document.querySelector('.container').innerHTML = dataStr

  }
  getList()

  async function getInfo() {
    const { data: { data: list } } = await axios.get(`/recipeInfo`, {
      params: {
        recipe_id: id
      }
    })

    let listStr = list.map((item, index) => {
      const { img, title, id } = item;
      return `
        <li>
          <a href="detail async-await.html"  data-id=${id}>
            <img src="http://124.223.14.236:3001/public/${img}" alt="" />
            <h3>${title}</h3>
          </a>
        </li>
      ` }).join('');
    document.querySelector('.list-box').innerHTML = listStr;
  }
  getInfo()

  $('.list-box').on('click', 'a', function () {
    const id = $(this).attr('data-id')
    localStorage.setItem('ajax06info', id)
  })




</script>

</html>